home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-23 | 58.4 KB | 1,872 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTwistDownApp.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1994-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTWISTDOWNAPP__
- #include "UTwistDownApp.h"
- #endif
-
- #ifndef __UTWISTDOWNDOCUMENT__
- #include "UTwistDownDocument.h"
- #endif
-
- #ifndef __UTWISTDOWNELEMENT__
- #include "UTwistDownElement.h"
- #endif
-
- #ifndef __UTWISTDOWNCONTROL__
- #include "UTwistDownControl.h"
- #endif
-
- #ifndef __UTWISTDOWNVIEW__
- #include "UTwistDownView.h"
- #endif
-
- //MacApp stuff
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h" //PPC
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h" //PPC
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h" //PPC
- #endif
-
- #ifndef __UDIALOG__
- #include "UDialog.h"
- #endif
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h" //PPC messageNewFailed
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h" //PPC
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __OBJECTHEAP__
- #include "ObjectHeap.h" //for MacApp 3.5
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h" //PPC gMacAppAppleEventIdleProc
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- #ifndef __UCLASSDESC__
- #include "UClassDesc.h"
- #endif
-
- #ifndef __UCLASSDESCITERATOR__
- #include "UClassDescIterator.h"
- #endif
-
- //ToolBox stuff
-
- #ifndef __AEREGISTRY__
- #include "AERegistry.h"
- #endif
-
- #ifndef __FONTS__ //required for the diamondMark used in the Windows menu
- #include "Fonts.h"
- #endif
-
- #ifndef __MENUS__
- #include "Menus.h"
- #endif
-
- #ifndef __RESOURCES__
- #include "Resources.h"
- #endif
-
- //ANSI stuff
- //None
-
- //----------------------------------------------------------------------------------------
- //gGlobals:
- TTwistDownApp* gTwistDownApp;
-
- //----------------------------------------------------------------------------------------
- // Constants:
-
-
-
- //========================================================================================
- // CLASS CWindowsMenuListIterator
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::CWindowsMenuListIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication,
- ArrayIndex itsLowBound, ArrayIndex itsHighBound, Boolean itsForward) :
- CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL,
- itsLowBound, itsHighBound, itsForward)
-
- {
- //not used, could take out?
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::CWindowsMenuListIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication,
- Boolean itsForward) :
- CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL, itsForward)
- {
- //not used, could take out?
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::CWindowsMenuListIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication) :
- CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL)
- {
- //used
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::~CWindowsMenuListIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- CWindowsMenuListIterator::~CWindowsMenuListIterator()
- {
-
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::CurrentWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- TWindow* CWindowsMenuListIterator::CurrentWindow()
- {
- return (TWindow*)this->CurrentObject();
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::FirstWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- TWindow* CWindowsMenuListIterator::FirstWindow()
- {
- return (TWindow*)this->FirstObject();
- }
- //----------------------------------------------------------------------------------------
- // CWindowsMenuListIterator::NextWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
- TWindow* CWindowsMenuListIterator::NextWindow()
- {
- return (TWindow*)this->NextObject();
- }
-
- //========================================================================================
- // CLASS TTwistDownApp
- //========================================================================================
- #undef Inherited
- #define Inherited TApplication
-
- #pragma segment MAInit
- MA_DEFINE_CLASS_M2(TTwistDownApp, Inherited, MVolumeBasedApp);
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::TTwistDownApp
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
- TTwistDownApp::TTwistDownApp() : MVolumeBasedApp()
- {
-
- gTwistDownApp = this;
- gSendAppleEvents = TRUE;
- gUseSystemDirection = TRUE;
- gAppleEventRouting = routeToDoc;
-
- fMainFileType = kFileType;
- fLaunchWithNewDocument = FALSE;
-
- fHasSplashScreen = !kHasSplashScreen; //For openers, assume no splash screen.
-
- fWindowsMenuList = NULL;
- fShowInvisibleFiles = FALSE;
-
- fAllowUnlimitedDocs = FALSE;
-
- fTDElementClassSize = 0; //the class size of TTwistDownElement
- fTDControlClassSize = 0; //the class size of TTwistDownControl
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::~TTwistDownApp
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TTwistDownApp::~TTwistDownApp()
- {
-
- fWindowsMenuList = (TList*)FreeListIfObject(fWindowsMenuList);
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::ITwistDownApp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
- void TTwistDownApp::ITwistDownApp(Boolean hasSplashScreen)
- {
- this -> IApplication(kFileType, kSignature);
-
- fHasSplashScreen = hasSplashScreen;
-
- fWindowsMenuList = NewList();
- #if qDebug
- fWindowsMenuList->SetEltType("TWindow");
- #endif
-
- AppendResMenu(MAGetMenu(mFontMenu), 'FONT');
-
- //The class size of TTwistDownElement and TTwistDownControl is used to determine
- //if there is enough space in the object heap to open a volume. Get their class sizes
- //now and save them, because later on when they're needed, there may not be enough space
- //left in the ObjectHeap to do it.
-
- TTwistDownElement* twistDownElement = new TTwistDownElement;
- CStr63 displayedText = gEmptyString;
- twistDownElement -> ITwistDownElement(NULL, 0, displayedText);
- fTDElementClassSize = (short)(twistDownElement -> GetClassSize());
- twistDownElement = (TTwistDownElement*)FreeIfObject(twistDownElement);
-
- TTwistDownControl* twistDownControl = new TTwistDownControl;
- VPoint itsLocation = gZeroVPt;
- twistDownControl -> ITwistDownControl(itsLocation, NULL,NULL);
- fTDControlClassSize = (short)(twistDownControl -> GetClassSize());
- twistDownControl = (TTwistDownControl*)FreeIfObject(twistDownControl);
-
- //Note: If IApplication can post a TEventRetrieverCommand, I can post
- //a TSplashScreenCommand here too.
- if (fHasSplashScreen)
- {
- TSplashScreenCommand* aSplashScreenCommand = NULL;
-
- aSplashScreenCommand = new TSplashScreenCommand;
- aSplashScreenCommand -> ISplashScreenCommand(cSplashScreen);
- this -> PostCommand(aSplashScreenCommand);
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::GetNextDocumentNumber: used by TTwistDownDocument::SetVolumeData:
- //----------------------------------------------------------------------------------------
- //Twist Down Lists can open the same volume many times. The following method is used to determine
- //the number of times a given volume has been opened. It returns a count of the number of times
- //a given volume has been opened plus 1. That value is used by
- //TTwistDownDocument::SetVolumeData(short volumeRefNumber, CStr31 volumeName)
- //to establish a unique document title. Note that scripting support requires that
- //documents have unique titles.
- #pragma segment AOpen
- short TTwistDownApp::GetNextDocumentNumber(const CStr31& volumeName)
- {
-
- short sameDocumentCount = 0;
- short highestSameDocumentNumber = 0;
-
- CDocumentIterator iter(this);
-
- for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- TTwistDownDocument* aTwistDownDocument = (TTwistDownDocument*)aDocument;
- CStr31 itsVolumeName = aTwistDownDocument -> fVolumeName;
-
- if (itsVolumeName == volumeName)
- {
- sameDocumentCount++;
- short thisSameDocumentNumber = aTwistDownDocument -> fSameVolumeNumber;
- if (thisSameDocumentNumber > highestSameDocumentNumber)
- highestSameDocumentNumber = thisSameDocumentNumber;
- }
- }
-
- if (sameDocumentCount == 0)
- return sameDocumentCount + 1;
- else
- return highestSameDocumentNumber + 1;
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::FindDocument: //analog of FindDocument, overloaded
- //----------------------------------------------------------------------------------------
- #pragma segment MAFile
- TDocument* TTwistDownApp::FindDocument(TVolume* aVolume)
- {
-
- CDocumentIterator iter(this);
-
- for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- TTwistDownDocument* aTwistDownDocument = (TTwistDownDocument*)aDocument;
- if (aTwistDownDocument -> FindDocument(aVolume))
- return aDocument;
- }
- return NULL; // No document already open
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoMakeDocument: overloaded
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- TDocument* TTwistDownApp::DoMakeDocument(CommandNumber aCommandNumber, TVolume* itsVolume)
- {
- #pragma unused aCommandNumber
- TTwistDownDocument* aTwistDownDocument = NULL;
-
- aTwistDownDocument = new TTwistDownDocument;
- aTwistDownDocument -> ITwistDownDocument(itsVolume, fShowInvisibleFiles);
-
- return aTwistDownDocument;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoSetupMenus
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownApp::DoSetupMenus()
- {
-
- #if qDebug
- if (gAppUserFlag3)
- {
- fprintf(stderr, ">TTwistDownApp::DoSetupMenus upon entry\n");
- PrintObjectCount();
- fprintf(stderr, "\n");
- DisplayMemoryInfo();
- }
- #endif
-
- MenuRef theWindowsMenuRef = NULL;
-
- short theNumberOfWindows = 0;
-
- CWindowsMenuListIterator iter(this);
- CStr255 theTitle = " ";
- CStr255 dummyTitle = "Dummy Title";
- short theMenuItem = 0;
-
- short counter = 0;
-
- Inherited::DoSetupMenus();
-
- Enable(cNew, FALSE);
- EnableCheck(cShowInvisibleFiles,TRUE, fShowInvisibleFiles);
-
- Boolean haveMemory = !MemSpaceIsLow();
- Enable(cOpen, haveMemory);
-
- theWindowsMenuRef = MAGetMenu(mWindowsMenu);
- LockHandle((Handle)theWindowsMenuRef);
- if(theWindowsMenuRef != NULL)
- theNumberOfWindows = CountMItems(theWindowsMenuRef);
-
- //first get rid of all the windows in the menu
-
- if (theNumberOfWindows != 0)
- for (counter = 1; counter <= theNumberOfWindows; counter++)
- {
- DeleteMenuItem(theWindowsMenuRef, 1);
- DisableItem(theWindowsMenuRef, 31);
- }
-
- //now, put them in
- theNumberOfWindows = this -> CountWindowsInList();
-
- if (theNumberOfWindows != 0)
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- {
- theMenuItem++;
- aWindow -> GetTitle(theTitle);
- AppendMenu(theWindowsMenuRef, dummyTitle); //in Menus.h
- SetMenuItemText(theWindowsMenuRef, theMenuItem, theTitle); //in Menus.h
- EnableItem(theWindowsMenuRef, theMenuItem);
- if (aWindow == this -> GetActiveWindow(kNoFloaters))
- SetItemMark(theWindowsMenuRef, theMenuItem, diamondMark);
- }
- HUnlock((Handle)theWindowsMenuRef);
-
-
- EnableCheck(cFailHere,TRUE, gFailHere);
- EnableCheck(cAllowUnlimitedDocs, TRUE, fAllowUnlimitedDocs);
- EnableCheck(cUseSystemDirection, TRUE, gUseSystemDirection );
- EnableCheck(cSendAppleEvents, TRUE, gSendAppleEvents);
-
- //Note: Though the cWritingDirection command is not accessible here, I want it to always be
- //in a known state. Without the following, the menuName seen by the user remains whatever
- //it was changed to by the last cWritingdirection command. Instances of TTwistDownView control
- //the command name seen for this item. However, if a twistDownView set it to Right-To-Left and
- //it is closed leaving no instance of TTwistDownView, then the command name seen for this item
- //would remain Right-To-Left. That is mightily disconcerting and, at first, you think the
- //application is acting up. Here we do make it behave consistently.
-
- if (GetSysDirection() == 0)
- SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kRightToLeftNameIdx);
- else
- SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kLeftToRightNameIdx);
-
- if (gAppleEventRouting == routeToDoc)
- SetIndividualCommandName(cAppleEventRouting, kMenuNameStrings, kRouteToViewNameIdx);
- else
- SetIndividualCommandName(cAppleEventRouting, kMenuNameStrings, kRouteToDocNameIdx);
-
-
- Enable(cAppleEventRouting, gSendAppleEvents);
-
- #if qDebug
- EnableCheck(cCountObjects, TRUE, gObjectCountingEnabled);
- Enable(cResetObjectCount, TRUE);
- EnableCheck(cPrintBaseClassInfo, TRUE, gPrintBaseClassInfo);
- EnableCheck(cPrintMacAppClassInfo, TRUE, gPrintMacAppClassInfo);
- EnableCheck(cPrintAppClassInfo, TRUE, gPrintAppClassInfo);
- EnableCheck(cAppUserFlag1, TRUE, gAppUserFlag1);
- EnableCheck(cAppUserFlag2, TRUE, gAppUserFlag2);
- EnableCheck(cAppUserFlag3, TRUE, gAppUserFlag3);
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoMenuCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TTwistDownApp::DoMenuCommand(CommandNumber aCommandNumber)
- {
- short theMenu = 0;
- short theMenuItem = 0;
- TWindow* newFrontWindow = NULL;
-
- CommandToMenuItem(aCommandNumber, theMenu, theMenuItem);
-
- if (theMenu == mWindowsMenu)
- {
- newFrontWindow = (TWindow*)fWindowsMenuList -> At(theMenuItem);
- if (newFrontWindow != (gApplication->GetActiveWindow(kNoFloaters)))
- newFrontWindow -> Select();
- }
- else
- switch (aCommandNumber)
- {
- case cShowInvisibleFiles:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pShowInvisibleFiles);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!fShowInvisibleFiles);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- fShowInvisibleFiles = !fShowInvisibleFiles;
- break;
-
- case cFailHere:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pFailHere);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gFailHere);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gFailHere = !gFailHere;
- break;
-
- case cAllowUnlimitedDocs:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pUnlimitedDocs);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!fAllowUnlimitedDocs);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- fAllowUnlimitedDocs = !fAllowUnlimitedDocs;
- break;
-
- case cSendAppleEvents:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() /*&& gSendAppleEvents*/)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSendAppleEvents);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gSendAppleEvents);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gSendAppleEvents = !gSendAppleEvents;
- break;
-
- //Question: If gUseSystemDirection == FALSE, some twistDownViews may be in right-to-left
- //while others are in left-to-right. When the user changes gUseSystemDirection to TRUE,
- //should those TTwistDownViews that are not currently using the system direction be
- //changed to use it? At present, they don't change and they're locked in what ever
- //writing direction they were using when gUseSystemDirection was changed to TRUE.
- case cUseSystemDirection:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pUseSystemDirection);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gUseSystemDirection);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gUseSystemDirection = !gUseSystemDirection;
- break;
-
- case cAppleEventRouting:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- DescType theAERouting;
-
- if (gAppleEventRouting == routeToDoc)
- theAERouting = kAERouteToView;
- else if(gAppleEventRouting == routeToView)
- theAERouting = kAERouteToDoc;
-
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pAERouting);
- CTempDesc theNewValue;
- theNewValue.PutEnum(theAERouting);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- {
- if (gAppleEventRouting == routeToDoc)
- gAppleEventRouting = routeToView;
- else if(gAppleEventRouting == routeToView)
- gAppleEventRouting = routeToDoc;
- }
- break;
-
- #if qDebug
- case cCountObjects:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pObjectCountingEnabled);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gObjectCountingEnabled);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gObjectCountingEnabled = !gObjectCountingEnabled;
- break;
-
- case cResetObjectCount:
- {
- TResetObjectCountCommand* aResetObjectCountCommand = new TResetObjectCountCommand;
- aResetObjectCountCommand -> IResetObjectCountCommand();
- if (gSendAppleEvents)
- aResetObjectCountCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(aResetObjectCountCommand);
- }
- break;
-
- case cPrintBaseClassInfo:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrBaseClassInfo);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gPrintBaseClassInfo);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gPrintBaseClassInfo = !gPrintBaseClassInfo;
- break;
-
- case cPrintMacAppClassInfo:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrMacAppClassInfo);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gPrintMacAppClassInfo);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gPrintMacAppClassInfo = !gPrintMacAppClassInfo;
- break;
-
- case cPrintAppClassInfo:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrAppClassInfo);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gPrintAppClassInfo);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gPrintAppClassInfo = !gPrintAppClassInfo;
- break;
-
- case cAppUserFlag1:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag1);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gAppUserFlag1);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gAppUserFlag1 = !gAppUserFlag1;
- break;
-
- case cAppUserFlag2:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag2);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gAppUserFlag2);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gAppUserFlag2 = !gAppUserFlag2;
- break;
-
- case cAppUserFlag3:
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag3);
- CTempDesc theNewValue;
- theNewValue.PutBoolean(!gAppUserFlag3);
- theEvent -> WriteParameter(keyAEData, theNewValue);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- gAppUserFlag3 = !gAppUserFlag3;
- break;
-
- #endif
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- } //end switch
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::AddWindowToWindowsMenuList
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownApp::AddWindowToWindowsMenuList(TWindow* windowToAdd)
- {
- if (fWindowsMenuList && (fWindowsMenuList->GetIdentityItemNo(windowToAdd) == 0))
- fWindowsMenuList->Insert(windowToAdd);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::RemoveWindowFromWindowsMenuList
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- void TTwistDownApp::RemoveWindowFromWindowsMenuList(TWindow* windowToRemove)
- {
- if (fWindowsMenuList && windowToRemove)
- fWindowsMenuList->Delete(windowToRemove);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::CountWindowsInList
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- short TTwistDownApp::CountWindowsInList()
- {
- MAVolatileInit(short, openWindows, 0);
- CWindowsMenuListIterator iter(this);
-
- if (!(fWindowsMenuList -> IsEmpty()))
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- if (aWindow)
- ++openWindows;
-
- return openWindows;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoMakeSplashScreen
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
- TWindow* TTwistDownApp::DoMakeSplashScreen()
- {
-
- TWindow* theSplashScreenWindow = NULL;
-
- CStr255 aString;
-
- this -> GetApplicationName(aString);
- MAParamText("^programName", aString);
-
- VersRecHndl vers1Info = (VersRecHndl)::GetResource(kVersInfoType, kVers1InfoID);
-
- if (vers1Info)
- aString = (**vers1Info).shortVersion;
- else
- aString = gEmptyString;
-
- MAParamText("^verStr", aString);
-
- FailInfo fi;
- Try(fi)
- {
- theSplashScreenWindow = gViewServer -> NewTemplateWindow(kAboutBoxWindowID, NULL);
-
- FailNIL(theSplashScreenWindow);
-
- if (theSplashScreenWindow)
- {
- TStaticText* theProgramNameStaticText = NULL;
- TStaticText* theCopyrightStaticText = NULL;
-
-
- theProgramNameStaticText = (TStaticText*) (theSplashScreenWindow -> FindSubView(kAboutProgNameViewID));
- theCopyrightStaticText = (TStaticText*) (theSplashScreenWindow -> FindSubView(kAboutCopyrightViewID));
-
-
- TButton* theOKButton = NULL;
- theOKButton = (TButton*) (theSplashScreenWindow -> FindSubView('ok '));
- theSplashScreenWindow -> RemoveSubView(theOKButton);
-
- //To create a memory leak, comment out the following statement.
- theOKButton = (TButton*)(FreeIfObject(theOKButton)); //otherwise would be orphaned.
-
- TDialogBehavior* itsDialogBehavior = theSplashScreenWindow -> GetDialogBehavior();
- if (itsDialogBehavior)
- theSplashScreenWindow -> RemoveBehavior (itsDialogBehavior);
-
- //To create a memory leak, comment out the following statement.
- itsDialogBehavior = (TDialogBehavior*)(FreeIfObject(itsDialogBehavior)); //otherwise would be orphaned.
-
-
- TextStyle theTextStyle = gApplicationStyle;
- CStr255 theFontName = "New Century Schoolbook";
- short theFontNumber;
- GetFNum(theFontName, &theFontNumber);
-
- short theFontSize = 24;
- if (theFontNumber != 0)
- theTextStyle.tsFont = theFontNumber;
-
- theTextStyle.tsSize = theFontSize;
-
- CRGBColor theColor = gRGBBlue;
-
- theProgramNameStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
- theProgramNameStaticText -> InstallColor(theColor, kDontRedraw);
-
- theFontSize = 12;
- theTextStyle.tsSize = theFontSize;
- theCopyrightStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
- theCopyrightStaticText -> InstallColor(theColor, kDontRedraw);
- }
- fi.Success();
- }
- else
- {
- theSplashScreenWindow = (TWindow*)(FreeIfObject(theSplashScreenWindow));
- theSplashScreenWindow = NULL;
- fi.ReSignal();
- }
-
- return theSplashScreenWindow;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoMakeAboutBox
- //----------------------------------------------------------------------------------------
- #pragma segment MAAboutApp
- TWindow* TTwistDownApp::DoMakeAboutBox()
- {
-
- TWindow* theAboutBoxWindow = NULL;
-
- CStr255 aString;
-
- this -> GetApplicationName(aString);
- MAParamText("^programName", aString);
-
- VersRecHndl vers1Info = (VersRecHndl)::GetResource(kVersInfoType, kVers1InfoID);
-
- if (vers1Info)
- aString = (**vers1Info).shortVersion;
- else
- aString = gEmptyString;
-
- MAParamText("^verStr", aString);
-
- FailInfo fi;
- Try(fi)
- {
- theAboutBoxWindow = gViewServer -> NewTemplateWindow(kAboutBoxWindowID, NULL);
-
- FailNIL(theAboutBoxWindow);
-
- if (theAboutBoxWindow)
- {
- TStaticText* theProgramNameStaticText = NULL;
- TStaticText* theCopyrightStaticText = NULL;
-
-
- theProgramNameStaticText = (TStaticText*) (theAboutBoxWindow -> FindSubView(kAboutProgNameViewID));
- theCopyrightStaticText = (TStaticText*) (theAboutBoxWindow -> FindSubView(kAboutCopyrightViewID));
-
- TextStyle theTextStyle = gApplicationStyle;
- CStr255 theFontName = "New Century Schoolbook";
- short theFontNumber;
- GetFNum(theFontName, &theFontNumber);
-
- short theFontSize = 24;
- if (theFontNumber != 0)
- theTextStyle.tsFont = theFontNumber;
-
- theTextStyle.tsSize = theFontSize;
-
- CRGBColor theColor = gRGBBlue;
-
- theProgramNameStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
- theProgramNameStaticText -> InstallColor(theColor, kDontRedraw);
-
- theFontSize = 12;
- theTextStyle.tsSize = theFontSize;
- theCopyrightStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
- theCopyrightStaticText -> InstallColor(theColor, kDontRedraw);
- }
- fi.Success();
- }
- else
- {
- theAboutBoxWindow = (TWindow*)(FreeIfObject(theAboutBoxWindow));
- fi.ReSignal();
- }
-
- return theAboutBoxWindow;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoAboutBox
- //----------------------------------------------------------------------------------------
- #pragma segment MAAboutApp
- void TTwistDownApp::DoAboutBox()
- {
- TWindow* theAboutBoxWindow = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- theAboutBoxWindow = this -> DoMakeAboutBox();
-
- if (theAboutBoxWindow)
- {
- theAboutBoxWindow -> PoseModally();
- theAboutBoxWindow -> CloseAndFree();
- }
- fi.Success();
- }
- else
- {
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::GetStandardFileParameters:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownApp::GetStandardFileParameters(CommandNumber itsCommandNumber,ProcPtr& fileFilter,
- TypeListHandle& typeList,short& dlgID,CPoint& where,ProcPtr& dlgHook,
- ProcPtr& modalFilter,Ptr& activeList,ProcPtr& activateProc,
- StandardFileReply* /*reply*/, void*& yourDataPtr)
- {
- dlgID = sfGetDialogID;
- where = kBestSystemLocation;
-
- this->GetFileTypeList(itsCommandNumber, typeList);
-
- fileFilter = (ProcPtr)gFileFilterYDProcPtr;
- dlgHook = (ProcPtr)gDlgHookYDProcPtr;
- modalFilter = (ProcPtr)gModalFilterYDProcPtr;
-
- activeList = NULL;
- activateProc = NULL;
- yourDataPtr = NULL;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoOpen:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownApp::DoOpen(CommandNumber theCmdNumber)
- {
-
- TList* aVolumeList = NULL; // passed by address
-
- if (this -> ChooseVolume(theCmdNumber, &aVolumeList))
- {
- TOVolumeCommand* anOVolumeCommand = new TOVolumeCommand;
- anOVolumeCommand -> IOVolumeCommand(theCmdNumber, aVolumeList);
- if (gSendAppleEvents)
- anOVolumeCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(anOVolumeCommand);
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::DoScriptCommand: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownApp::DoScriptCommand(CommandNumber aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
- {
- switch (aCommandNumber)
- {
- case cFinderOpen:
- {
- TOVolumeCommand * anOVolumeCommand = new TOVolumeCommand;
- anOVolumeCommand->IOVolumeCommand(aCommandNumber, message->fMessage, reply->fMessage);
- this->PostCommand(anOVolumeCommand);
- }
- break;
-
- #if qDebug
- case cResetObjectCount:
- {
- TResetObjectCountCommand* aResetObjectCountCommand = new TResetObjectCountCommand;
- aResetObjectCountCommand -> IResetObjectCountCommand(message -> fMessage, reply -> fMessage);
- this -> PostCommand(aResetObjectCountCommand);
- }
- break;
- #endif
-
- default:
- {
- Inherited::DoScriptCommand(aCommandNumber, message, reply);
- }
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::CountContainedObjects:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- long TTwistDownApp::CountContainedObjects(DescType desiredType)
- {
- long result = 0;
-
- switch (desiredType)
- {
- case cTwistDownView:
- {
- CNoGhostDocsIterator iter(this);
- for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- if (aDocument -> GetOMClass() == cDocument)
- result++;
- }
- break;
-
- default:
- {
- result = Inherited::CountContainedObjects(desiredType);
- }
- break;
- }
-
- return result;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::GetContainedObject:
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
- MScriptableObject* TTwistDownApp::GetContainedObject(DescType desiredType,
- DescType selectionForm,const CAEDesc& selectionData)
- {
-
- MScriptableObject* result = NULL;
- TTwistDownView* theTwistDownView = NULL;
- TTwistDownDocument* theTwistDownDocument = NULL;
-
- if (desiredType == cTwistDownView && selectionForm == formName)
- {
- CStr255 theName;
- selectionData.GetString(theName);
- CNoGhostDocsIterator iter(this);
- for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- if (aDocument != NULL)
- {
- CStr255 name = gEmptyString;
- aDocument -> GetTitle(name);
- if (name == theName)
- {
- theTwistDownDocument = (TTwistDownDocument*)aDocument;
- theTwistDownView = theTwistDownDocument -> fTwistDownView;
- result = theTwistDownView;
- return result;
- }
- }
- }
-
- }
- else if (desiredType == cDocument && selectionForm == formName)
- {
- //Note: MacApp 3.3.1 TApplication::GetContainedObject dose not work if a script
- //attempts to get a document that does not exist. In the case where there are
- //no open documents, the result is an access fault. Therefore, I'm using the
- //following substitute code.
- CStr255 theName;
- selectionData.GetString(theName);
- CNoGhostDocsIterator iter(this);
-
- for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- if (aDocument != NULL)
- {
- CStr255 name = gEmptyString;
- aDocument -> GetTitle(name);
- if (name == theName)
- {
- theTwistDownDocument = (TTwistDownDocument*)aDocument;
- result = theTwistDownDocument;
- return result;
- }
- }
- }
- }
- else
- {
- result = Inherited::GetContainedObject(desiredType, selectionForm, selectionData);
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::GetSetPropertyInfo: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownApp::GetSetPropertyInfo(DescType whichProperty,CommandNumber& cmdNum,
- Boolean& canUndo,Boolean& causesChange,TCommandHandler* &theContext)
- {
-
- switch(whichProperty)
- {
-
- case pShowInvisibleFiles:
- cmdNum = cShowInvisibleFiles;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pUseSystemDirection:
- cmdNum = cUseSystemDirection;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pSendAppleEvents:
- cmdNum = cSendAppleEvents;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pFailHere:
- cmdNum = cFailHere;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pUnlimitedDocs:
- cmdNum = cAllowUnlimitedDocs;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pAERouting:
- cmdNum = cAppleEventRouting;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- #if qDebug
- case pObjectCountingEnabled:
- cmdNum = cCountObjects;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pPrBaseClassInfo:
- cmdNum = cPrintBaseClassInfo;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pPrMacAppClassInfo:
- cmdNum = cPrintMacAppClassInfo;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pPrAppClassInfo:
- cmdNum = cPrintAppClassInfo;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pSetAppUserFlag1:
- cmdNum = cAppUserFlag1;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pSetAppUserFlag2:
- cmdNum = cAppUserFlag2;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pSetAppUserFlag3:
- cmdNum = cAppUserFlag3;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
- #endif
-
- default:
- Inherited::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::SetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownApp::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- Boolean newValue = FALSE;
- CAEDesc localPropValue = thePropertyValue;
- switch (whichProperty)
- {
- case pShowInvisibleFiles:
- newValue = thePropertyValue.GetBoolean();
- fShowInvisibleFiles = newValue;
- break;
-
- case pUseSystemDirection:
- newValue = thePropertyValue.GetBoolean();
- gUseSystemDirection = newValue;
- break;
-
- case pSendAppleEvents:
- newValue = thePropertyValue.GetBoolean();
- gSendAppleEvents = newValue;
- break;
-
- case pFailHere:
- newValue = thePropertyValue.GetBoolean();
- gFailHere = newValue;
- break;
-
- case pUnlimitedDocs:
- newValue = thePropertyValue.GetBoolean();
- fAllowUnlimitedDocs = newValue;
- break;
-
- case pAERouting:
- DescType theAERouting = thePropertyValue.GetEnum();
- if (theAERouting == kAERouteToDoc)
- gAppleEventRouting = routeToDoc;
- else
- gAppleEventRouting = routeToView;
- break;
-
- #if qDebug
- case pObjectCountingEnabled:
- newValue = thePropertyValue.GetBoolean();
- gObjectCountingEnabled = newValue;
- break;
-
- case pPrBaseClassInfo:
- newValue = thePropertyValue.GetBoolean();
- gPrintBaseClassInfo = newValue;
- break;
-
- case pPrMacAppClassInfo:
- newValue = thePropertyValue.GetBoolean();
- gPrintMacAppClassInfo = newValue;
- break;
-
- case pPrAppClassInfo:
- newValue = thePropertyValue.GetBoolean();
- gPrintAppClassInfo = newValue;
- break;
-
- case pSetAppUserFlag1:
- newValue = thePropertyValue.GetBoolean();
- gAppUserFlag1 = newValue;
- break;
-
- case pSetAppUserFlag2:
- newValue = thePropertyValue.GetBoolean();
- gAppUserFlag2 = newValue;
- break;
-
- case pSetAppUserFlag3:
- newValue = thePropertyValue.GetBoolean();
- gAppUserFlag3 = newValue;
- break;
- #endif
-
- default:
- Inherited::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownApp::GetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- Boolean TTwistDownApp::GetObjectProperty(CAEDesc& thePropertyValue,DescType whichProperty,const CAEDesc& desiredType)
- {
-
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
- case pShowInvisibleFiles:
- thePropertyValue.PutBoolean(fShowInvisibleFiles);
- break;
-
- case pUseSystemDirection:
- thePropertyValue.PutBoolean(gUseSystemDirection);
- break;
-
- case pSendAppleEvents:
- thePropertyValue.PutBoolean(gSendAppleEvents);
- break;
-
- case pFailHere:
- thePropertyValue.PutBoolean(gFailHere);
- break;
-
- case pUnlimitedDocs:
- thePropertyValue.PutBoolean(fAllowUnlimitedDocs);
- break;
-
- case pAERouting:
- DescType theAERouting;
- if (gAppleEventRouting == routeToDoc)
- theAERouting = kAERouteToDoc;
- else
- theAERouting = kAERouteToView;
-
- thePropertyValue.PutEnum(theAERouting);
- break;
-
- #if qDebug
- case pObjectCountingEnabled:
- thePropertyValue.PutBoolean(gObjectCountingEnabled);
- break;
-
- case pPrBaseClassInfo:
- thePropertyValue.PutBoolean(gPrintBaseClassInfo);
- break;
-
- case pPrMacAppClassInfo:
- thePropertyValue.PutBoolean(gPrintMacAppClassInfo);
- break;
-
- case pPrAppClassInfo:
- thePropertyValue.PutBoolean(gPrintAppClassInfo);
- break;
-
- case pSetAppUserFlag1:
- thePropertyValue.PutBoolean(gAppUserFlag1);
- break;
-
- case pSetAppUserFlag2:
- thePropertyValue.PutBoolean(gAppUserFlag2);
- break;
-
- case pSetAppUserFlag3:
- thePropertyValue.PutBoolean(gAppUserFlag3);
- break;
- #endif
-
- default:
- hasProperty = Inherited::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else
- {
- // we failed while trying to get the property
- hasProperty = FALSE;
-
- // Don't ReSignal
- }
- return hasProperty;
- }
-
- //========================================================================================
- // CLASS TVolumesCommand analog of TFilesCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TVolumesCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TVolumesCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TVolumesCommand::TVolumesCommand()
- {
- fCausesChange = FALSE;
- fVolumeList = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TVolumesCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- TVolumesCommand::~TVolumesCommand()
- {
- fVolumeList = (TList*)FreeListIfObject(fVolumeList);
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TVolumesCommand::IVolumesCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TVolumesCommand::IVolumesCommand(CommandNumber itsCommandNumber,
- TList* theDocuments)
- {
-
- this -> IServerCommand(itsCommandNumber, gApplication, kCantUndo, kDoesNotCauseChange, NULL);
- fVolumeList = theDocuments;
-
- }
- //----------------------------------------------------------------------------------------
- // TVolumesCommand::IVolumesCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TVolumesCommand::IVolumesCommand(CommandNumber itsCommandNumber,
- const AppleEvent& itsMessage,
- const AppleEvent& itsReply) // override
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off.
- this -> IServerCommand(itsCommandNumber, gApplication, kCantUndo, kDoesNotCauseChange, NULL,
- itsMessage, itsReply);
-
- // Check to see what is in the direct object list
- this -> GetVolumesList();
-
- }
- //----------------------------------------------------------------------------------------
- // TVolumesCommand::GetVolumesList: analog of TFilesCommand::GetFilesList:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TVolumesCommand::GetVolumesList()
- {
-
- // Check to see what is in the direct object list
- CAEDesc directObj;
- FailOSErr(AEGetParamDesc(&fMessage->fMessage, keyDirectObject, typeAEList, directObj));
- long theCount = 0;
- FailOSErr(AECountItems(directObj, &theCount));
- if (theCount > 0)
- {
- // Get the first descriptor and see what type it is
- DescType theKey;
- CTempDesc theDesc;
-
- FailOSErr(AEGetNthDesc(directObj, 1, typeWildCard, &theKey, theDesc));
-
- MAVolatileInit(THandleList*, aHandleList, NULL);
- MAVolatileInit(TList*, aVolumeList, NULL);
-
- FailInfo outerFi;
- Try(outerFi)
- {
- aHandleList = new THandleList;
- aHandleList->IHandleList();
-
- FailInfo innerfi;
- Try(innerfi)
- {
- aVolumeList = NewList();
-
- fMessage->ReadHandleList(keyDirectObject, typeAlias, aHandleList);
-
- // Block is necessary for correct failure handling
- {
- CHandleIterator iter(aHandleList);
-
- for (Handle item = iter.FirstHandle(); iter.More(); item = iter.NextHandle())
- {
- MAVolatileInit(TVolume*, aVolume, NULL);
-
- aVolume = gTwistDownApp -> DoMakeVolume();
-
- FailInfo onemorefi;
- Try(onemorefi)
- {
- FailOSErr(aVolume -> SpecifyWithAlias(AliasHandle(item)));
- aVolumeList->InsertLast(aVolume);
- onemorefi.Success();
- }
- else
- {
- aVolume = (TVolume*)FreeIfObject(aVolume);
- onemorefi.ReSignal();
- }
-
- aHandleList->Delete(item); // Delete it from the list so if we fail
- // we don't try to free it twice
- item = DisposeIfHandle(item);
- }
- }
- innerfi.Success();
- }
- else // Recover
- {
-
- if (aHandleList)
- aHandleList->FreeList();
-
- if (aVolumeList)
- aVolumeList->FreeList();
-
- innerfi.ReSignal();
- }
- outerFi.Success();
- }
- else
- {
-
- this->Free();
- outerFi.ReSignal();
- }
-
- aHandleList->Free(); // It is just a list of disposed handles…
-
- fVolumeList = aVolumeList;
- directObj.DisposeDesc();
- }
-
- }
- //========================================================================================
- // CLASS TOVolumeCommand analog of TODocCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TVolumesCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TOVolumeCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TOVolumeCommand::TOVolumeCommand()
- {
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TOVolumeCommand::~TOVolumeCommand()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand::IOVolumeCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TOVolumeCommand::IOVolumeCommand(CommandNumber itsCommandNumber,
- TList* theDocuments)
- {
- this->IVolumesCommand(itsCommandNumber, theDocuments);
- }
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand::IOVolumeCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TOVolumeCommand::IOVolumeCommand(CommandNumber itsCommandNumber, const AppleEvent& itsMessage, const AppleEvent& itsReply)
- {
- this->IVolumesCommand(itsCommandNumber, itsMessage, itsReply);
- }
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TOVolumeCommand::DoIt()
- {
- gTwistDownApp -> OpenVolume(fIdentifier, fVolumeList);
- }
- //----------------------------------------------------------------------------------------
- // TOVolumeCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
- TAppleEvent* TOVolumeCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, theEvent, NULL);
- CTempDesc theList;
-
- FailInfo fi;
- Try(fi)
- {
- theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kCoreEventClass, kAEOpenDocuments, gServerAddress, kAEWaitReply);
- theList.CreateList();
- {
- CObjectIterator iter(fVolumeList);
- for (TVolume * aVolume = (TVolume *)iter.FirstObject(); iter.More(); aVolume = (TVolume *)iter.NextObject())
- {
- AliasHandle theAlias = NULL;
- OSErr theErr = aVolume -> GetAlias(theAlias);
- if (theErr == noErr)
- {
- CAEDesc theAliasDesc(typeAlias, (Handle)theAlias);
- theList.PutListItem(0, theAliasDesc);
- }
- }
- }
- theEvent->WriteParameter(keyDirectObject, theList);
- fi.Success();
- }
- else // Recover
- {
- theEvent = (TAppleEvent *)FreeIfObject(theEvent);
- fi.ReSignal();
- }
- return theEvent;
- }
- //========================================================================================
- // CLASS TOpenVolumeCommand - old version, not used
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TOpenVolumeCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TOpenVolumeCommand: Empty constructor to satisfy the compiler. - old version
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TOpenVolumeCommand::TOpenVolumeCommand()
- {
- fVolume = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TOpenVolumeCommand destructor - old version
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TOpenVolumeCommand::~TOpenVolumeCommand()
- {
- fVolume = NULL;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TOpenVolumeCommand::IOpenVolumeCommand: - old version
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TOpenVolumeCommand::IOpenVolumeCommand(CommandNumber itsCommandNumber,TVolume* theVolume)
- {
- this -> ICommand(itsCommandNumber, NULL,kCantUndo,kDoesNotCauseChange,NULL);
- fVolume = theVolume;
- }
- //----------------------------------------------------------------------------------------
- // TOpenVolumeCommand::DoIt: - old version
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TOpenVolumeCommand::DoIt()
- {
-
- gTwistDownApp -> OpenVolume(fIdentifier, fVolume);
-
- }
-
- #if qDebug
- //========================================================================================
- // CLASS TResetObjectCountCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TResetObjectCountCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TResetObjectCountCommand::TResetObjectCountCommand()
- {
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- TResetObjectCountCommand::~TResetObjectCountCommand()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand::IResetObjectCountCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TResetObjectCountCommand::IResetObjectCountCommand()
- {
- this -> IServerCommand(cResetObjectCount, gTwistDownApp, kCantUndo, kDoesNotCauseChange, NULL);
- }
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand::IResetObjectCountCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TResetObjectCountCommand::IResetObjectCountCommand(const AppleEvent& itsMessage,const AppleEvent& itsReply)
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off. Note that it must be set
- //before IServerCommand is called.
-
- this -> IServerCommand(cResetObjectCount, gTwistDownApp, kCantUndo, kDoesNotCauseChange, NULL,
- itsMessage, itsReply);
-
- }
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- TAppleEvent* TResetObjectCountCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, theResetObjectCountEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- theResetObjectCountEvent = new TAppleEvent;
- theResetObjectCountEvent -> IAppleEvent(kAETwistDownListsSuite, kAEResetObjectCountID,gServerAddress, kAENoReply);
- {
- CTempDesc directObjectDesc;
- gTwistDownApp -> MakeObjectSpecifier(directObjectDesc, gTwistDownApp -> GetSpecifierForm());
- theResetObjectCountEvent -> WriteParameter(keyDirectObject, directObjectDesc);
- }
- fi.Success();
- }
- else // Recover
- {
- theResetObjectCountEvent = (TAppleEvent *)FreeIfObject(theResetObjectCountEvent);
- fi.ReSignal();
- }
-
- return theResetObjectCountEvent;
- }
- //----------------------------------------------------------------------------------------
- // TResetObjectCountCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TResetObjectCountCommand::DoIt()
- {
- gObjectCount = 1; //Must set to 1 to account for this object, TResetObjectCountCommand,
- //being freed.
- }
- #endif
- //========================================================================================
- // CLASS TSplashScreenCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment AInit
- MA_DEFINE_CLASS_M1(TSplashScreenCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSplashScreenCommand::TSplashScreenCommand
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
- TSplashScreenCommand::TSplashScreenCommand()
- {
- fSplashScreenWindow = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TSplashScreenCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
- TSplashScreenCommand::~TSplashScreenCommand()
- {
- if (fSplashScreenWindow)
- fSplashScreenWindow = (TWindow*)(FreeIfObject(fSplashScreenWindow));
-
- fSplashScreenWindow = NULL;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TSplashScreenCommand::ISplashScreenCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
- void TSplashScreenCommand::ISplashScreenCommand(CommandNumber itsCommandNumber)
- {
- this -> ICommand(itsCommandNumber, NULL, kCantUndo, kDoesNotCauseChange, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- fSplashScreenWindow = gTwistDownApp -> DoMakeSplashScreen();
- fi.Success();
- }
- else
- {
- fSplashScreenWindow = (TWindow*)(FreeIfObject(fSplashScreenWindow));
- fi.ReSignal();
- }
- }
- //----------------------------------------------------------------------------------------
- // TSplashScreenCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
- void TSplashScreenCommand::DoIt()
- {
-
- if (fSplashScreenWindow)
- {
- fSplashScreenWindow -> Open();
- fSplashScreenWindow -> Update();
-
- long theTickCount;
- Delay(60, &theTickCount);
-
- fSplashScreenWindow -> CloseAndFree();
- fSplashScreenWindow = NULL;
- }
- }
-
- #pragma segment Inline